//
//  HourseDataManage.m
//  WGFGlobalHouses
//
//  Created by welldone on 15/5/4.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "HourseDataManage.h"
#import "HomeNewSiteCellModel.h"
#import "HomeNewSiteLabModel.h"
#import "API.h"
#import "JSONKit.h"
#import "UserModal.h"
#import "HourseDetailData.h"
#import "StringTool.h"

#import "NearbyCellData.h"
#import "HourseDetailData.h"
#import "HourseCagegoryData.h"
#import "HourseMapCellData.h"
#import "HourseCagegoryCellData.h"
#import "UserModal.h"
#import "config.h"
#import "NSString+StringHight.h"
#import "CommentData.h"
#import "MBProgressHUD+MJ.h"
#import "AFNetworking.h"
#import "ImgCache.h"




@interface HourseDataManage ()
@property (nonatomic,assign)int pageIndex,pageIndex2;

@end

@implementation HourseDataManage
@synthesize pageIndex,pageIndex2;




-(ResulteMod*)refreshDataWithCache:(BOOL)caChe{
    
    pageIndex = 1;
    
    NSString *url = [NSString stringWithFormat:@"%@%zd/%d/8",[API urlMake:HourseList],[UserModal shareUserModel].userId,pageIndex];
    
    
    ResulteMod *mod;
    if (caChe) {
        mod = [Connect doGetWithCaChe:url];
    }else{
        mod = [Connect doGetWithOutCaChe:url];
    }
    
    
    if (![mod.resultCode isEqualToString:@"20003"]){
        mod.resltState = ResultFail;
        mod.resultTip  = ![StringTool isBlankString:mod.resultDic[@"message"]]?mod.resultDic[@"message"]:[StringTool isBlankString:mod.resultCode]?@"网络错误":[NSString stringWithFormat:@"网络错误%@",mod.resultCode];
        return mod;
    }
    
    NSDictionary *resDic = mod.resultDic;
    
    NSDictionary *abstractResponseDic = resDic[@"abstractResponse"];
    NSArray *mianArray = abstractResponseDic[@"dtos"];
    
    
    NSMutableArray *array = [[NSMutableArray alloc]init];
    for (NSDictionary *itemDic in mianArray) {
        
        HomeNewSiteCellModel *mod = [HomeNewSiteCellModel new];
        mod.maxRate = [NSString stringWithFormat:@"%@",itemDic[@"maxCommitionRate"]];
        mod.title = itemDic[@"title"];
        mod.imgUrl = [API imgUrlMake:itemDic[@"thumb"]];
        mod.hourseStauts = [itemDic[@"premisesStatus"] intValue];
        mod.hourseId= itemDic[@"housingId"];
        
        mod.totalAmountUSD = [NSString stringWithFormat:@"%ld",(long)[itemDic[@"totalAmountUSD"] integerValue]];
        
        NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
        
        formatter.numberStyle = NSNumberFormatterDecimalStyle;
        
        NSString *totalAmountCNY = [formatter stringFromNumber:[NSNumber numberWithInteger:[itemDic[@"totalAmountCNY"]integerValue]]];
        
        
        mod.totalAmountCNY = [NSString stringWithFormat:@"约￥%@万",totalAmountCNY];
        
        mod.openDateWithHour = itemDic[@"openingDate"];
        mod.expiryDate = itemDic[@"expiryDate"];
        
        NSDateFormatter *form =[[NSDateFormatter alloc] init];
        [form setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *openDate=[FTWCache getLocData:[form dateFromString:mod.openDateWithHour]];
        
        [form setDateFormat:@"yyyy-MM-dd"];
        NSString *dateString=[form stringFromDate:openDate];
        mod.openDate = [NSString stringWithFormat:@"开盘时间:%@",dateString];
        
        mod.currentDate = itemDic[@"currentTime"];
        
        
        //        int minRent = [itemDic[@"minRent"] intValue];
        int maxRent = [itemDic[@"maxRent"] intValue];
        //        int rent = (minRent + maxRent)/2;
        
        int maxYeild = [itemDic[@"maxYield"] intValue];
        //        int minYeild = [itemDic[@"minYield"] intValue];
        //        int yeild = (maxYeild+minYeild)/2;
        
        NSMutableArray *tagArray = [[NSMutableArray alloc]init];
        [tagArray addObject:[NSString stringWithFormat:@" 租金:$%d/月 ",maxRent]];
        [tagArray addObject:[NSString stringWithFormat:@" 收益率:%d%@ ",maxYeild,@"%"]];
        mod.labArr = tagArray;
        
        mod.address = [NSString stringWithFormat:@"%@-%@-%@",itemDic[@"countryName"],itemDic[@"stateName"],itemDic[@"cityName"]];
        
        [array addObject:mod];
    }
    
    if (array.count>0) {
        pageIndex++;
    }
    
    mod.dataMod = array;
    
    
    return mod;
}




-(ResulteMod*)loadMoreData{
    
    NSString *url = [NSString stringWithFormat:@"%@%zd/%d/8",[API urlMake:HourseList],[UserModal shareUserModel].userId,pageIndex];
    
    ResulteMod *mod = [Connect doGetWithCaChe:url];
    
    if (![mod.resultCode isEqualToString:@"20003"] && ![mod.resultCode isEqualToString:@"0"]){
        mod.resltState = ResultFail;
        return mod;
    }
    
    NSDictionary *resDic = mod.resultDic;
    
    NSDictionary *abstractResponseDic = resDic[@"abstractResponse"];
    NSArray *mianArray = abstractResponseDic[@"dtos"];
    
    
    NSMutableArray *array = [[NSMutableArray alloc]init];
    for (NSDictionary *itemDic in mianArray) {
        
        HomeNewSiteCellModel *mod = [HomeNewSiteCellModel new];
        mod.maxRate = [NSString stringWithFormat:@"%@%@",itemDic[@"maxCommitionRate"],@"%"];
        mod.title = itemDic[@"title"];
        mod.imgUrl = [API imgUrlMake:itemDic[@"thumb"]];
        mod.hourseStauts = [itemDic[@"premisesStatus"] intValue];
        mod.hourseId= itemDic[@"housingId"];
        
        mod.totalAmountUSD = [NSString stringWithFormat:@"%ld",(long)[itemDic[@"totalAmountUSD"] integerValue]];
        
        mod.totalAmountCNY = [NSString stringWithFormat:@"约￥%@万",itemDic[@"totalAmountCNY"]];
        
        mod.openDateWithHour = itemDic[@"openingDate"];
        NSDateFormatter *form =[[NSDateFormatter alloc] init];
        [form setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *openDate=[FTWCache getLocData:[form dateFromString:mod.openDateWithHour]];
        
        [form setDateFormat:@"yyyy-MM-dd"];
        NSString *dateString=[form stringFromDate:openDate];
        mod.openDate = [NSString stringWithFormat:@"开盘时间:%@",dateString];
        mod.expiryDate = itemDic[@"expiryDate"];
        mod.currentDate = itemDic[@"currentTime"];
        
        int minRent = [itemDic[@"minRent"] intValue];
        int maxRent = [itemDic[@"maxRent"] intValue];
        int rent = (minRent + maxRent)/2;
        
        int maxYeild = [itemDic[@"maxYield"] intValue];
        int minYeild = [itemDic[@"minYield"] intValue];
        int yeild = (maxYeild+minYeild)/2;
        
        NSMutableArray *tagArray = [[NSMutableArray alloc]init];
        [tagArray addObject:[NSString stringWithFormat:@"租金:$%d/月",rent]];
        [tagArray addObject:[NSString stringWithFormat:@"收益率:%d%@",yeild,@"%"]];
        mod.labArr = tagArray;
        
        mod.address = [NSString stringWithFormat:@"%@-%@-%@",itemDic[@"countryName"],itemDic[@"stateName"],itemDic[@"cityName"]];
        
        [array addObject:mod];
    }
    
    if (array.count>0) {
        pageIndex++;
    }
    
    mod.dataMod = array;
    
    return mod;
}



-(ResulteMod*)refreshDetailData:(NSString*)dataId{
    
    NSMutableArray *dataArray = [[NSMutableArray alloc]init];
    
    NSString *url = [NSString stringWithFormat:@"%@%@/%ld",[API urlMake:HourseDetail],dataId,(long)[UserModal shareUserModel].userId];
    
    ResulteMod *mod = [Connect doGetWithCaChe:url];
    
    if (![mod.resultCode isEqualToString:@"20003"]){
        mod.resltState = ResultFail;
        return mod;
    }
    
    NSDictionary *resDic = mod.resultDic;
    
    NSDictionary *abstractResponseDic = resDic[@"abstractResponse"];
    NSDictionary *mianDic = abstractResponseDic[@"detailDto"];
    
    if (mianDic.count==0) {
        return mod;
    }
    
    
    HourseDetailData *mainData = [[HourseDetailData alloc]init];
    mainData.dataId = [NSString stringWithFormat:@"%@",mianDic[@"housingId"]];
    [mainData setMainImgUrl:[API imgUrlMake:mianDic[@"thumb"]]];
    [mainData setTitle:mianDic[@"housingName"]];
    [mainData setAddress:[NSString stringWithFormat:@"%@-%@-%@",mianDic[@"countryName"],mianDic[@"stateName"],mianDic[@"cityName"]]];
    [mainData setOpenTimeWithHour:mianDic[@"openingDate"]];
    
    mainData.expiryDate = mianDic[@"expiryDate"];
    
    NSDateFormatter *form =[[NSDateFormatter alloc] init];
    [form setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *openDate=[FTWCache getLocData:[form dateFromString:mainData.openTimeWithHour]];
    
    [form setDateFormat:@"yyyy-MM-dd"];
    NSString *dateString=[form stringFromDate:openDate];
    mainData.openTime = dateString;
    

    NSMutableArray *imgMuArray = [[NSMutableArray alloc]init];
    if ([StringTool isBlankString:mianDic[@"videoPicPath"]]==false&&[UserModal shareUserModel].userType!=UserTypeCustomer) {
        [imgMuArray addObject:[API videoUrlMake:mianDic[@"videoPicPath"]]];
    }
    
    
    NSArray *imgArray = mianDic[@"imagePath"];
    
    if (![imgArray isKindOfClass:[NSNull class]]) {
        for (NSString *img in imgArray) {
            [imgMuArray addObject:[API imgUrlMake:img]];
        }
    }else{
        imgMuArray = nil;
    }
    
    mainData.photoShowImgArray = imgMuArray;
    
    
    
    
    //    NSInteger dols = [mianDic[@"totalAmountUSD"] integerValue];
    mainData.dol= [NSString stringWithFormat:@"%@",mianDic[@"totalAmountUSD"]];
    
    mainData.rmb = [NSString stringWithFormat:@"%@",mianDic[@"totalAmountCNY"]];
    
    mainData.maxRate = mianDic[@"maxCommitionRate"];
    
    mainData.hourseCode= mianDic[@"businessNo"];
    mainData.area = mianDic[@"areaMi"];
    mainData.baoZhu = mianDic[@"baozu"];
    mainData.huiGou = mianDic[@"huigou"];
    
    
    mainData.rent = [NSString stringWithFormat:@"%d/月",[mianDic[@"maxRent"] intValue]];
    mainData.rentRate = [NSString stringWithFormat:@"%d%%",[mianDic[@"maxYield"] intValue]];
    
    //    mainData.rent = [StringTool isBlankString:mianDic[@"expectedRent"]]?@"":mianDic[@"expectedRent"];
    //    mainData.rentRate = [StringTool isBlankString:mianDic[@"expectedYield"]]?@"":mianDic[@"expectedYield"];
    
    mainData.progressState = [mianDic[@"saleStatus"] intValue];
    
    mainData.allCount = [NSString stringWithFormat:@"%@",mianDic[@"xianfangCount"]];
    mainData.saledCount = [NSString stringWithFormat:@"%@",mianDic[@"saledCount"]];
    
    
    mainData.saleBookUrl = [API pdfUrlMake:mianDic[@"sellBook"]];
    mainData.customBookUrl = [API pdfUrlMake:mianDic[@"cusBook"]];
    
    if ([StringTool isBlankString:mianDic[@"videoUrl"]]==false) {
        mainData.videoUrl = [API videoUrlMake:mianDic[@"videoUrl"]];
    }
    
    
    NSArray *array = mianDic[@"sellingList"];
    NSString *maiStr = array.firstObject;
    
    NSInteger size = [array count];
    for (int i=1;i<size;i++) {
        NSString *str = [array objectAtIndex:i];
        maiStr = [NSString stringWithFormat:@"%@\n%@",maiStr,str];
    }
    
    mainData.maiDetailHtml = maiStr;
    
    mainData.maiDetail = [StringTool isBlankString:mianDic[@"sellTitle"]]?@"无数据":mianDic[@"sellTitle"];
    
    
    
    array = mianDic[@"breaksList"];
    NSString *huiStr = array.firstObject;
    size = [array count];
    for (int i=1;i<size;i++) {
        NSString *str = [array objectAtIndex:i];
        huiStr = [NSString stringWithFormat:@"%@\n%@",maiStr,str];
    }
    mainData.huiDetail = huiStr;
    
    NSArray *yongLis = mianDic[@"yongjinList"];
    if (yongLis.count>0) {
        NSArray *firstItem = yongLis.firstObject;
        
        if (firstItem.count>1) {
            mainData.yongDetail = [NSString stringWithFormat:@"签约日起的第一个月的销售业绩满>=%@套",firstItem.firstObject];
            mainData.yongRedDetail = [NSString stringWithFormat:@"签约日起的第二个月可获取分销佣金%@%%",firstItem.lastObject];
        }
        
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc]init];
        
        
        
        for (NSArray *itemArray in yongLis) {
            if (itemArray.count>1) {
                
                NSString *org = [NSString stringWithFormat:@"签约日起的第一个月的销售业绩满>=%@套\n",itemArray.firstObject];
                
                NSMutableAttributedString *orgAtt = [[NSMutableAttributedString alloc]initWithAttributedString:[org attributedStringFromStingWithFont:[UIFont systemFontOfSize:14] withLineSpacing:3]];
                
                [orgAtt addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize:14]
                                        range: NSMakeRange(0, org.length)];
                [orgAtt addAttribute: NSForegroundColorAttributeName value: [UIColor redColor] range: NSMakeRange(0, org.length)];
                 
                 org = [NSString stringWithFormat:@"签约日起的第二个月可获取分销佣金%@%%\n\n",itemArray.lastObject];
                 NSMutableAttributedString *rateAtt = [[NSMutableAttributedString alloc]initWithAttributedString:[org attributedStringFromStingWithFont:[UIFont systemFontOfSize:14] withLineSpacing:3]];
                
                [rateAtt addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize:14]
                               range: NSMakeRange(0, org.length)];
                [rateAtt addAttribute: NSForegroundColorAttributeName value: UIColorFromRGB(0x333333) range: NSMakeRange(0, org.length)];

                 [str appendAttributedString:orgAtt];
                 [str appendAttributedString:rateAtt];
            }
        }
        
        mainData.yongDetailAtt = str;
    }
    
    
    
    
    
    NSString *detailStr = mianDic[@"surSchool"];
    if (![StringTool isBlankString:detailStr]) {
        NearbyCellData *data = [[NearbyCellData alloc]init];
        [data setCELL_STYLE:CELL_STYLE_NearBy];
        [data setTitle:@"周边学校"];
        [data setDetail:detailStr];
        [data setMoreDetial:[StringTool isBlankString:mianDic[@"surSchoolDetail"]]?@" ":mianDic[@"surSchoolDetail"]];
        [dataArray addObject:data];
    }
    
    
    detailStr = mianDic[@"aroundEnv"];
    if (![StringTool isBlankString:detailStr]) {
        NearbyCellData *data = [[NearbyCellData alloc]init];
        [data setCELL_STYLE:CELL_STYLE_NearBy];
        [data setTitle:@"周边环境"];
        [data setDetail:detailStr];
        [dataArray addObject:data];
    }
    
    
    detailStr = mianDic[@"communityFac"];
    if (![StringTool isBlankString:detailStr]) {
        NearbyCellData *data = [[NearbyCellData alloc]init];
        [data setCELL_STYLE:CELL_STYLE_NearBy];
        [data setTitle:@"周边设施"];
        [data setDetail:detailStr];
        [dataArray addObject:data];
    }
    
    detailStr = mianDic[@"surroundingFac"];
    if (![StringTool isBlankString:detailStr]) {
        NearbyCellData *data = [[NearbyCellData alloc]init];
        [data setCELL_STYLE:CELL_STYLE_NearBy];
        [data setTitle:@"周边配套"];
        [data setDetail:detailStr];
        [dataArray addObject:data];
    }
    
    detailStr = mianDic[@"leisureFac"];
    if (![StringTool isBlankString:detailStr]) {
        NearbyCellData *data = [[NearbyCellData alloc]init];
        [data setCELL_STYLE:CELL_STYLE_NearBy];
        [data setTitle:@"休闲设施"];
        [data setDetail:detailStr];
        [dataArray addObject:data];
    }
    
    detailStr = mianDic[@"healthFit"];
    if (![StringTool isBlankString:detailStr]) {
        NearbyCellData *data = [[NearbyCellData alloc]init];
        [data setCELL_STYLE:CELL_STYLE_NearBy];
        [data setTitle:@"健康健身"];
        [data setDetail:detailStr];
        [dataArray addObject:data];
    }
    
    detailStr = mianDic[@"spfac"];
    if (![StringTool isBlankString:detailStr]) {
        NearbyCellData *data = [[NearbyCellData alloc]init];
        [data setCELL_STYLE:CELL_STYLE_NearBy];
        [data setTitle:@"汽电设施"];
        [data setDetail:detailStr];
        [dataArray addObject:data];
    }
    
    detailStr = mianDic[@"housingFac"];
    if (![StringTool isBlankString:detailStr]) {
        NearbyCellData *data = [[NearbyCellData alloc]init];
        [data setCELL_STYLE:CELL_STYLE_NearBy];
        [data setTitle:@"房源配套"];
        [data setDetail:detailStr];
        [dataArray addObject:data];
    }
    
    
    detailStr = mianDic[@"detail"];
    if (![StringTool isBlankString:detailStr]) {
        NearbyCellData *data = [[NearbyCellData alloc]init];
        [data setCELL_STYLE:CELL_STYLE_Detail];
        [data setTitle:@"详细介绍"];
        [data setDetail:detailStr];
        [dataArray addObject:data];
    }
    
    
    
    
    NSArray *categorys = mianDic[@"chamber"];
    if (categorys.count>0) {
        
        HourseCagegoryCellData *data = [[HourseCagegoryCellData alloc]init];
        data.CELL_STYLE = CELL_STYLE_HOURSE_CATEGORY;
        
        data.allCouont = [mianDic[@"housingCount"] intValue];
        
        NSDictionary *dic = categorys.firstObject;
        HourseCagegoryData *leftData = [[HourseCagegoryData alloc]init];
        [leftData setDataId:dic[@"id"]];
        [leftData setTitle:@"楼盘房型A"];
        [leftData setImgUrl:[API imgUrlMake:dic[@"thumb"]]];
        [leftData setArea:[NSString stringWithFormat:@"%@m²",dic[@"floorArea"]]];
        [leftData setGeJu:[NSString stringWithFormat:@"卧室:%@间  卫浴:%@间",dic[@"bedroom"],dic[@"bathroom"]]];
        data.leftData = leftData;
        
        
        if (categorys.count>1) {
            
            NSDictionary *dic = categorys.lastObject;
            HourseCagegoryData *leftData = [[HourseCagegoryData alloc]init];
            [leftData setTitle:@"楼盘房型B"];
            [leftData setDataId:dic[@"id"]];
            [leftData setImgUrl:[API imgUrlMake:dic[@"thumb"]]];
            [leftData setArea:[NSString stringWithFormat:@"%@m²",dic[@"floorArea"]]];
            [leftData setGeJu:[NSString stringWithFormat:@"卧室:%@间  卫浴:%@间",dic[@"bedroom"],dic[@"bathroom"]]];
            data.rightData = leftData;
        }
        
        mainData.houseCatCellData = data;
    }
    
    
    
    float lat = [mianDic[@"latitude"] floatValue];
    float lng = [mianDic[@"longitude"] floatValue];
    if (lat!=0&lng!=0) {
        
        HourseMapCellData *data = [[HourseMapCellData alloc]init];
        data.CELL_STYLE = CELL_STYLE_HOURSE_MAP;
        CLLocationCoordinate2D dd =CLLocationCoordinate2DMake(lat, lng);
        [data setTitle:mianDic[@"address"]];
        //        [data setTitle:mianDic[@"housingName"]];
        //        [data setSubtitle:mianDic[@"address"]];
        [data setCoordinate:dd];
//        data.coordinate = CLLocationCoordinate2DMake(39.90923, 116.397428);
         data.coordinate = CLLocationCoordinate2DMake(lat, lng);
        [dataArray addObject:data];
    }
    
    
    
    mainData.arrayData = dataArray;
    
    mod.dataMod = mainData;
    
    return mod;
}




-(ResulteMod*)refreshAllCommentData:(NSString*)houreseId pageIndex:(int)index{
    
    NSMutableDictionary *dic = [NSMutableDictionary new];
    [dic setObject:[NSNumber numberWithInt:index] forKey:@"currPage"];
    [dic setObject:@"10" forKey:@"perItem"];
    [dic setObject:houreseId forKey:@"qryPremisesId"];
    [dic setObject:@"1" forKey:@"haveAttachment"];
    
    ResulteMod *mod = [Connect doPostOutCaCheWithUrl:[API urlMake:HourseCommentList] withParamDic:dic];
    
    NSMutableArray *array = [NSMutableArray new];
    if ([mod.resultCode isEqualToString:@"20003"]){
        mod.resltState = ResultSuccess;

        NSDictionary *comDic = [mod.resultDic objectForKey:@"dtos"];
        for (NSDictionary *dic in comDic) {
            
            CommentData *data = [CommentData new];
            NSDictionary *userDic = [dic objectForKey:@"consumerInfo"];
            [data setUserId:[userDic objectForKey:@"consumerId"]];
            [data setHeadImgPath:[API pdfUrlMake:[userDic objectForKey:@"avatar"]]];
            [data setNickName:[userDic objectForKey:@"nickName"]];
            
            [data setCommentDetail:[dic objectForKey:@"commentContent"]];
            
            NSMutableArray *imgPaths = [NSMutableArray new];
            NSArray *imgArray = [dic objectForKey:@"thumbs"];
            for (NSString *img in imgArray) {
                [imgPaths addObject:[API pdfUrlMake:img]];
            }
            [data setImgArray:imgPaths];
            [array addObject:data];
        }
        
        mod.dataMod = array;
        
    }else{
        mod.resltState = ResultFail;
    }
   
    return mod;
}





#pragma mark 首页搜索楼盘
-(ResulteMod *)searchPremiseListWithKeyWord:(NSString *)keyword;
{
    pageIndex2 = 1;
    NSString *url = [API urlMake:prmisesSearch];
    NSString *consumerId = [NSString stringWithFormat:@"%zd",[UserModal shareUserModel].userId];
    NSString *currPage = [NSString stringWithFormat:@"%zd",pageIndex2];
    NSDictionary *dict =  @{@"consumerId":consumerId,@"currPage":currPage,@"perItem":@"8",@"qryName":keyword};;
   
    ResulteMod *mod;
    
   
    mod = [Connect doPostOutCaCheWithUrl:url withParamDic:dict];
    

    if (![mod.resultCode isEqualToString:@"20003"]&&![mod.resultCode isEqualToString:@"0"]){
        mod.resltState = ResultFail;
        mod.resultTip  = ![StringTool isBlankString:mod.resultDic[@"message"]]?mod.resultDic[@"message"]:[StringTool isBlankString:mod.resultCode]?@"网络错误":[NSString stringWithFormat:@"网络错误%@",mod.resultCode];
        return mod;
    }
    
    NSDictionary *resDic = mod.resultDic;
    
//    NSDictionary *abstractResponseDic = resDic[@"abstractResponse"];
//    NSArray *mianArray = abstractResponseDic[@"dtos"];
//    NSDictionary *abstractResponseDic = resDic[@"abstractResponse"];
    NSArray *mianArray = resDic[@"dtos"];

    
    
    NSMutableArray *array = [[NSMutableArray alloc]init];
    for (NSDictionary *itemDic in mianArray) {
        
        HomeNewSiteCellModel *mod = [HomeNewSiteCellModel new];
        mod.maxRate = [NSString stringWithFormat:@"%@",itemDic[@"maxCommitionRate"]];
        mod.title = itemDic[@"title"];
        mod.imgUrl = [API imgUrlMake:itemDic[@"thumb"]];
        mod.hourseStauts = [itemDic[@"premisesStatus"] intValue];
        mod.hourseId= itemDic[@"housingId"];
        
        mod.totalAmountUSD = [NSString stringWithFormat:@"%ld",(long)[itemDic[@"totalAmountUSD"] integerValue]];
        
        NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
        
        formatter.numberStyle = NSNumberFormatterDecimalStyle;
        
        NSString *totalAmountCNY = [formatter stringFromNumber:[NSNumber numberWithInteger:[itemDic[@"totalAmountCNY"]integerValue]]];
        
        
        mod.totalAmountCNY = [NSString stringWithFormat:@"约￥%@万",totalAmountCNY];
        
        mod.openDateWithHour = itemDic[@"openingDate"];
        mod.expiryDate = itemDic[@"expiryDate"];
        
        NSDateFormatter *form =[[NSDateFormatter alloc] init];
        [form setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *openDate=[FTWCache getLocData:[form dateFromString:mod.openDateWithHour]];
        
        [form setDateFormat:@"yyyy-MM-dd"];
        NSString *dateString=[form stringFromDate:openDate];
        mod.openDate = [NSString stringWithFormat:@"开盘时间:%@",dateString];
        
        mod.currentDate = itemDic[@"currentTime"];
        
        
        //        int minRent = [itemDic[@"minRent"] intValue];
        int maxRent = [itemDic[@"maxRent"] intValue];
        //        int rent = (minRent + maxRent)/2;
        
        int maxYeild = [itemDic[@"maxYield"] intValue];
        //        int minYeild = [itemDic[@"minYield"] intValue];
        //        int yeild = (maxYeild+minYeild)/2;
        
        NSMutableArray *tagArray = [[NSMutableArray alloc]init];
        [tagArray addObject:[NSString stringWithFormat:@" 租金:$%d/月 ",maxRent]];
        [tagArray addObject:[NSString stringWithFormat:@" 收益率:%d%@ ",maxYeild,@"%"]];
        mod.labArr = tagArray;
        
        mod.address = [NSString stringWithFormat:@"%@-%@-%@",itemDic[@"countryName"],itemDic[@"stateName"],itemDic[@"cityName"]];
        
        [array addObject:mod];
    }
    
    if (array.count>0) {
        pageIndex2++;
    }
    
    mod.dataMod = array;
    
    
    return mod;

}

#pragma mark 首页搜索加载更多
-(ResulteMod *)LoadMoresearchPremiseListWithKeyWord:(NSString *)keyword{
    
    NSString *url = [API urlMake:prmisesSearch];
    NSString *consumerId = [NSString stringWithFormat:@"%zd",[UserModal shareUserModel].userId];
    NSString *currPage = [NSString stringWithFormat:@"%zd",pageIndex2];
    NSDictionary *dict =  @{@"consumerId":consumerId,@"currPage":currPage,@"perItem":@"8",@"qryName":keyword};;
    
    
    ResulteMod *mod;
    
    mod = [Connect doPostOutCaCheWithUrl:url withParamDic:dict];
    
    if (![mod.resultCode isEqualToString:@"20003"] && ![mod.resultCode isEqualToString:@"0"]){
        mod.resltState = ResultFail;
        mod.resultTip  = ![StringTool isBlankString:mod.resultDic[@"message"]]?mod.resultDic[@"message"]:[StringTool isBlankString:mod.resultCode]?@"网络错误":[NSString stringWithFormat:@"网络错误%@",mod.resultCode];
        return mod;
    }
    
    NSDictionary *resDic = mod.resultDic;
    
    NSDictionary *abstractResponseDic = resDic[@"abstractResponse"];
    NSArray *mianArray = abstractResponseDic[@"dtos"];
    
    
    NSMutableArray *array = [[NSMutableArray alloc]init];
    for (NSDictionary *itemDic in mianArray) {
        
        HomeNewSiteCellModel *mod = [HomeNewSiteCellModel new];
        mod.maxRate = [NSString stringWithFormat:@"%@%@",itemDic[@"maxCommitionRate"],@"%"];
        mod.title = itemDic[@"title"];
        mod.imgUrl = [API imgUrlMake:itemDic[@"thumb"]];
        mod.hourseStauts = [itemDic[@"premisesStatus"] intValue];
        mod.hourseId= itemDic[@"housingId"];
        
        NSInteger dols = [itemDic[@"totalAmountUSD"] integerValue];
        mod.totalAmountUSD = [NSString stringWithFormat:@"$%.0ld",(long)dols];
        
        mod.totalAmountCNY = [NSString stringWithFormat:@"约￥%@万",itemDic[@"totalAmountCNY"]];
        
        mod.openDateWithHour = itemDic[@"openingDate"];
        NSDateFormatter *form =[[NSDateFormatter alloc] init];
        [form setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *openDate=[FTWCache getLocData:[form dateFromString:mod.openDateWithHour]];
        
        [form setDateFormat:@"yyyy-MM-dd"];
        NSString *dateString=[form stringFromDate:openDate];
        mod.openDate = [NSString stringWithFormat:@"开盘时间:%@",dateString];
        
        mod.currentDate = itemDic[@"currentTime"];
        
        int minRent = [itemDic[@"minRent"] intValue];
        int maxRent = [itemDic[@"maxRent"] intValue];
        int rent = (minRent + maxRent)/2;
        
        int maxYeild = [itemDic[@"maxYield"] intValue];
        int minYeild = [itemDic[@"minYield"] intValue];
        int yeild = (maxYeild+minYeild)/2;
        
        NSMutableArray *tagArray = [[NSMutableArray alloc]init];
        [tagArray addObject:[NSString stringWithFormat:@"租金:$%d/月",rent]];
        [tagArray addObject:[NSString stringWithFormat:@"收益率:%d%@",yeild,@"%"]];
        mod.labArr = tagArray;
        
        mod.address = [NSString stringWithFormat:@"%@-%@-%@",itemDic[@"countryName"],itemDic[@"stateName"],itemDic[@"cityName"]];
        
        [array addObject:mod];
    }
    
    if (array.count>0) {
        pageIndex2++;
    }
    
    mod.dataMod = array;
    
    return mod;

}

-(void)addComment:(NSString *)hourseID withString:(NSString*)comment withImgs:(NSArray*)array with:(FinishCallBack)call{
    
    
    
    __block ResulteMod *mod = [[ResulteMod alloc]init];
    
    if (comment.length<15) {
        [mod setResltState:ResultFail];
        [mod setResultTip:@"字数少于15个"];
        call(mod);
        return;
    }else if (comment.length>200){
    
        [mod setResltState:ResultFail];
        [mod setResultTip:@"不能超过200个字符"];
        call(mod);
        return;
        
    }
    
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSMutableDictionary *dic = [NSMutableDictionary new];
        [dic setObject:hourseID forKey:@"premisesId"];
        [dic setObject:[NSNumber numberWithInteger:[UserModal shareUserModel].userId ]forKey:@"consumerId"];
        [dic setObject:comment forKey:@"content"];
        
        mod = [Connect doPostOutCaCheWithUrl:[API urlMake:AddComment] withParamDic:dic];
        
        if ([mod.resultCode isEqualToString:@"20003"]) {
            [mod setResltState:ResultSuccess];
            
            if (array.count>0) {
                
                AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
                manager.responseSerializer = [AFJSONResponseSerializer serializer];
                
                //  manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
                manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
                
                NSString *url = [NSString stringWithFormat:@"%@%@",[API urlMake:AddCommentPic],[mod.resultDic objectForKey:@"premisesCommentId"]];
                
                [manager POST:url parameters:nil constructingBodyWithBlock:^(id formData) {
                    
                    for (NSString *key in array) {
                        [formData appendPartWithFileData:[ImgCache objectForKey:key] name:@"avatar" fileName:@"application.jpg" mimeType:@"image/jpeg"];
                    }
                    
                } success:^(AFHTTPRequestOperation *operation, id responseObject) {
                    
                    [mod setResltState:ResultSuccess];
                    
                } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                    
                    [mod setResltState:ResultFail];
                }];
            }
            
            
        }else{
            [mod setResltState:ResultFail];
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            call(mod);
            
        });
    });
}

#pragma mark 获取广告图片
-(ResulteMod *)getAdvertise;
{
    NSString *url = [API urlMake:advertise];
    ResulteMod *mod;
    mod = [Connect doGetWithOutCaChe:url];
    
    
    if (![mod.resultCode isEqualToString:@"20003"]&&![mod.resultCode isEqualToString:@"0"]){
        mod.resltState = ResultFail;
        mod.resultTip  = ![StringTool isBlankString:mod.resultDic[@"message"]]?mod.resultDic[@"message"]:[StringTool isBlankString:mod.resultCode]?@"网络错误":[NSString stringWithFormat:@"网络错误%@",mod.resultCode];
        return mod;
    }
    NSDictionary *resDic = mod.resultDic;
    NSArray *arr = [[NSArray alloc]initWithArray:resDic[@"advertises"]];
    mod.dataMod = arr;
    
    return mod;
}
@end
